<template>
  <el-cascader :props="props" v-bind="$attrs" v-model="myValue" @change="cascaderChange" clearable :key="key"></el-cascader>
</template>
<script>
import request from '@/utils/request';
export default {
  props: {
        value: {
            type: Array,
            default: false
        }
    },
  data() {
    return {
      myValue:'',
      key:0,
      props: {
          lazy: true,
          lazyLoad:this.cascaderLoad
        }
    }
  },
  methods: {
    updata(){
      this.myValue = this.value
      this.key++
    },
    cascaderChange(e) {
      this.$emit('input', e)
      this.$emit('change', e)
    },
   async cascaderLoad(node, resolve) {

      const { level, pathNodes } = node;
      let data = {
        countryCode:"CN"
      }
      if (pathNodes) {
        if (pathNodes.length > 0) data.provDistCd = pathNodes[0].label
        if (pathNodes.length > 1) data.cityDistCd = pathNodes[1].label
      }

      request.post("/admin/region/selectAddress", data)
        .then((data) => {
          if (data) {
            resolve(data.map(it => {
              return {
                value: it.regionId,
                label: it.address,
                leaf:it.isLeaf==="Y"
              }
            }));
          }
        })
    },
  },
}
</script>
